package net.xiduth.game.player.content.grandexchange;

import java.io.Serializable;

import net.xiduth.game.World;
import net.xiduth.game.item.Item;
import net.xiduth.game.player.Player;
import net.xiduth.game.player.content.exchange.ItemOffer.OfferType;

/**
 * @author Tyluur <itstyluur@gmail.com>
 * @since 2012-08-17
 */
public class GrandExchangeOffer implements Serializable {

	private static final long serialVersionUID = 883724604061077341L;
	
	private Player owner;
	private Item item;
	private OfferType type;
	private int slot;
	private int offeredAmount;
	private int offeredPrice;
	private int amountCompleted;
	
	public GrandExchangeOffer(Player owner, Item item, int slot, OfferType type, int offeredAmount, int offeredPrice, int amountCompleted) {
		this.owner = owner;
		this.item = item;
		this.slot = slot;
		this.type = type;
		this.offeredAmount = offeredAmount;
		this.offeredPrice = offeredPrice;
		this.amountCompleted = amountCompleted;
	}
	
	public Player getOwner() {
		return World.getPlayer(owner.getUsername());
	}

	public void setOwner(Player owner) {
		this.owner = owner;
	}

	public Item getItem() {
		return item;
	}

	public void setItem(Item item) {
		this.item = item;
	}

	public OfferType getType() {
		return type;
	}

	public void setType(OfferType type) {
		this.type = type;
	}

	public int getSlot() {
		return slot;
	}

	public void setSlot(int slot) {
		this.slot = slot;
	}

	public int getOfferedPrice() {
		return offeredPrice * offeredAmount;
	}
	
	public int getFirstPrice() {
		return offeredPrice;
	}

	public void setOfferedPrice(int offeredPrice) {
		this.offeredPrice = offeredPrice;
	}

	public int getOfferedAmount() {
		return offeredAmount;
	}

	public void setOfferedAmount(int offeredAmount) {
		this.offeredAmount = offeredAmount;
	}

	public int getAmountCompleted() {
		return amountCompleted;
	}

	public void setAmountCompleted(int amountCompleted) {
		this.amountCompleted = amountCompleted;
	}
	
	public void updateAmountCompleted(int amount) {
		amountCompleted += amount;
	}

	public boolean isFinished() {
		return offeredAmount == amountCompleted;
	}

}
